﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.ComponentModel;

namespace MLY.Bll
{
    [DataObject]
    public class clsOrganizationClassification
    {

        #region Constructors
        // ==================================
        public clsOrganizationClassification()
        {
           using (Dal.lqKbmDataContext db = new MLY.Dal.lqKbmDataContext(g.AppConnectionString))
            {
            _DataRow = new Dal.TableOrganizationClassification();
            IsExist = false;
           }
        }

        public clsOrganizationClassification(int OrgId)
        {
            using (Dal.lqKbmDataContext db = new MLY.Dal.lqKbmDataContext(g.AppConnectionString))
            {
                _DataRow = (from o in db.TableOrganizationClassifications
                            where (o.OrganizationId == OrgId)
                            select o).FirstOrDefault();

                IsExist = _DataRow != null;
                if (!IsExist)
                    _DataRow = new MLY.Dal.TableOrganizationClassification();
            }
        }

        public void deleteOrganizationClassification(int OrgId)
        {
            using (Dal.lqKbmDataContext db = new MLY.Dal.lqKbmDataContext(g.AppConnectionString))
            {
            Dal.TableOrganizationClassification row =
                (from o in db.TableOrganizationClassifications
                 where (o.OrganizationId == OrgId)
                 select o).FirstOrDefault();
            IsExist = _DataRow != null;
            db.TableOrganizationClassifications.DeleteOnSubmit(row);
            db.SubmitChanges();
            }
        }
        // ==================================
        #endregion

        #region Static Members
        // ==================================





        // ==================================
        #endregion

        #region Public Methods
        // ==================================


        public void Save()
        {
            using (Dal.lqKbmDataContext dc = new MLY.Dal.lqKbmDataContext())
            {
                if (IsExist)
                {
                    deleteOrganizationClassification(_DataRow.OrganizationId);
                }

                dc.TableOrganizationClassifications.InsertOnSubmit(_DataRow);
                dc.SubmitChanges();
            }
        }
        // ==================================
        #endregion

        #region Public Properties
        // ==================================
        public Dal.TableOrganizationClassification Data
        {
            get { return _DataRow; }
        }
        // ==================================
        #endregion

        #region Fields
        // ==================================
        public bool IsExist = false;
        //Dal.lqKbmDataContext _db = null;
        Dal.TableOrganizationClassification _DataRow = null;
        // ==================================
        #endregion
    }
}